package com.bensonbasement.snorflux.client;

import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;

import com.bensonbasement.snorflux.client.states.CommandSelectState;
import com.bensonbasement.snorflux.commands.ItemData;
import com.bensonbasement.snorflux.messages.fromserver.CommandRequestMessage;

public class VerbsPane extends JPanel {
	
	public VerbsPane(final CommandRequestMessage request, final CommandSelectState callback) {
		Font sectionsFont = new Font("Courier New",Font.BOLD,16);
		
		setLayout(new BoxLayout(this,BoxLayout.Y_AXIS));
		
		JButton endTurnButton = new JButton("END TURN");
		endTurnButton.setFocusable(false);
		endTurnButton.setFont(sectionsFont);
		endTurnButton.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				callback.endTurnChosen();
			}
		});
		add(endTurnButton);
		
		JLabel infoLabel = new JLabel("AP: "+request.getCurrentAP());
		add(infoLabel);
		if (!request.getStuffHere().isEmpty()) {
			add(Box.createVerticalStrut(10));
			JLabel stuffHereLabel = new JLabel("Stuff here:");
			stuffHereLabel.setAlignmentX(LEFT_ALIGNMENT);
			stuffHereLabel.setFont(sectionsFont);
			add(stuffHereLabel);
			for (ItemData item : request.getStuffHere()) {
				ItemPanel itemPanel = new ItemPanel(item,request.getCurrentAP(),callback);
				itemPanel.setAlignmentX(LEFT_ALIGNMENT);
				add(itemPanel);
			}
		}
		if (!request.getInventory().isEmpty()) {
			add(Box.createVerticalStrut(10));
			JLabel inventoryLabel = new JLabel("Inventory:");
			inventoryLabel.setAlignmentX(LEFT_ALIGNMENT);
			inventoryLabel.setFont(sectionsFont);
			add(inventoryLabel);
			for (ItemData item : request.getInventory()) {
				ItemPanel itemPanel = new ItemPanel(item,request.getCurrentAP(),callback);
				itemPanel.setAlignmentX(LEFT_ALIGNMENT);
				add(itemPanel);
			}
		}
	}
}
